<template>
	<view class="enroll-view">

		<!-- <view v-for="(question,index) in questions" :key="index">
			<ztext v-if="question.type=='ztext'" :que="question.question" :restrict="question.answer.restrict" :length="question.answer.length" :empty="question.answer.empty" :ref="question.key" />
			<zradio v-if="question.type=='zradio'" :que="question.question" :choices="question.answer.choices" :empty="question.answer.empty" :ref="question.key" />
			<zcheckbox v-if="question.type=='zcheckbox'" :que="question.question" :choices="question.answer.choices" :minNum="question.answer.minNum" :maxNum="question.answer.maxNum" :ref="question.key" />
			<zpicker v-if="question.type=='zpicker'" :que="question.question" :choices="question.answer.choices" :empty="question.answer.empty" :ref="question.key" />
			
		</view> -->
		<!-- 报名成功 -->
		<view class="enroll-item dashboard"><text class="item-name">报名id</text><text class="item-content">{{eId}}</text></view>
		<view class="enroll-item dashboard"><text class="item-name">状态提示</text><text class="item-content">{{statusTip}}</text></view>

		<view v-if="status==2" class="enroll-item dashboard"><text class="item-name">报名拒绝原因</text><text class="item-content">{{rejectReason}}</text></view>
		<view class="enroll-item dashboard"><text class="item-name">提交时间</text><text class="item-content">{{submitTime}}</text></view>
		<text style="text-align:center;height:100upx;font-size:40upx;padding-top:20upx;" >提交表单内容</text>
		<zEnrollAnsPanel :answer="content"/>
		
	</view>
</template>


<script>
	import formatDatetime from "../../common/zdateutil.js"
	import zEnrollAnsPanel from "../../components/basic/zenrollanspanel";
	export default {
		data() {
			return {
				eId : "",
				statusTip : "",
				submitTime : "",
				status : -1,
				content : [],
				rejectReason : ""
				// keys : []
			}
		},
		components : {
			zEnrollAnsPanel
		},
		onLoad(option) {
			// this.$refs.q1.question = "大象的鼻子有多长？"
			// console.log(option.eId)
			this.eId = option.eId;
			var param = {'eId':option.eId};
			// console.log(param);
			// 获取报名的全部情况
			this.statusTip = option.statusTip;

			var vm = this;
			// 如果状态没有传递过来，获取状态
			if(option.status == null){
				var param = {'eId':option.eId};
				this.$get(this.enrollurl + '/enroll/enrollResult',param,function(res){
					var data = res.data;
					if(data.code != 0){
						uni.showModal({
							title : '错误',
							content : data.message,
							showCancel : false
						})
						return ;
					}
					// console.log(data.object)
					// 获取得到的状态
					vm.status = data.object.status;
					if(vm.status == -1){
						// 返回到填写页面
						uni.navigateTo({
							url : './fillEnroll?eId=' + vm.eId
						})
					}
					// vm.status = option.status;
					vm.statusTip = data.object.statusTip;
					vm.submitTime = formatDatetime.formatDatetime(new Date(parseInt(data.object.submit_time)));
					vm.content = JSON.parse(data.object.content);
					vm.eId = option.eId;
					vm.rejectReason = data.object.reject_reason;
				})
			}else{
				this.status = option.status;
				this.statusTip = option.statusTip;
				this.submitTime = formatDatetime.formatDatetime(new Date(parseInt(option.submitTime)));
				this.content = JSON.parse(option.content);
				this.eId = option.eId;
				this.rejectReason = option.reject_reason;
				// console.log(option.statusTip + ' ' + option.submitTime + ' ' + option.content + ' ' + option.status)
			}


			// this.eId = option.eId;
			// // var formatDatatime = formatDatatime;
			// var vm = this;
			// this.$get(this.enrollurl + '/enroll/getEnrollMeta',param,function(res){
			// 	var data = res.data;
			// 	if(data.code != 0){
			// 		uni.showModal({
			// 			title : '错误',
			// 			content : data.message,
			// 			showCancel : false
			// 		})
			// 		return ;
			// 	}
			// 	data = data.object;
			// 	vm.questions = eval('(' + data.content + ')');
			// 	if((data.endMethod >> 1 & 1) == 1){
			// 		vm.planEndTime = formatDatetime.formatDatetime(new Date(data.planEndTime));
			// 		// console.log(vm.planEndTime)
			// 	}
			// 	vm.status = data.status;
			// 	// console.log(data.content)
			// });
			// var data = '[{"question":"您的年龄？","key":"q1","type":"ztext","answer":{"restrict":0,"length":2,"empty":true}},{"question":"您的性别？","key":"q4","type":"zradio","answer":{"choices":["男","女"],"empty":false}}]';
			// this.questions = eval('(' + data + ')');
			// for(var i=0;i<this.questions.length;i++){
			// 	this.keys.push(this.questions[i].key);
			// }
		},
		methods: {
			getStatusText : function(status){
				if(status == 0) return '进行中';
				else return '已终止';
			},
			submit : function(){
				// console.log(this.keys)
				// window.test = this.$refs
				// console.log(this.$refs)
				// .answerPanel.get()
				// console.log()
				var content = this.$refs.answerPanel.get();
				if(content == null)
					return ;
				var param = {'eId':this.eId,'content':JSON.stringify(this.$refs.answerPanel.get())}
				this.$post(this.enrollurl + '/enroll/submitEnroll',param,function(res){
					var data = res.data;
					if(data.code != 0){
						uni.showModal({
							title : '错误',
							content : data.message,
							showCancel : false
						})
						return ;
					}
					
				});
				// console.log(this.$refs.q1.get())
				// console.log(this.$refs.q2.get())
				// console.log(this.$refs.q3.get())
				// console.log(this.$refs.q4.get())
			}
		}
	}
</script>

<style>
	@import "../../common/zcss.css";
	/* .input{
		width:200upx;
	} */
	.enroll-view{
		flex-direction: column;
		width: 100%;
	}
	.enroll-item{
		border-bottom: 1upx solid gray;
		border-top: 1upx solid gray;
		width: 100%;
		height:50upx;
		padding-top: 10upx;
		/* background-color: white; */
		position: relative;
	}
	.item-name{
		position: absolute;
		left: 1%;
		color: gray;
	}
	.item-content{
		position: absolute;
		right: 1%;
	
	}
</style>
